<?php 
$model = new Administrator_Model_Product_View();
$title = 'Danh sách sản phẩm';
$button = '<button class="add button" name="btadd" value="btadd" type="submit"></button>';
switch ($this->task) {
	case 'new':
	$title = 'Thêm sản phẩm';
	$button = '<button title="Lưu" class="save button" name="btsave" value="btsave" type="submit"></button>';
	$button .= '<button title="Quay lại" class="back button" name="btback" value="btback" type="submit"></button>';
	$button .= '<button title="Trang chủ" class="option button" name="btoption" value="btoption" type="submit"></button>';
	break;
	case 'edit':
	$title = 'Thay đổi thông tin sản phẩm';
	$button = '<button title="Lưu" class="save button" name="btsave" value="btsave" type="submit"></button>';
	$button .= '<button title="Quay lại" class="back button" name="btback" value="btback" type="submit"></button>';
	$button .= '<button title="Trang chủ" class="option button" name="btoption" value="btoption" type="submit"></button>';
	break;
	case 'list':
	$title = 'Danh sách sản phẩm';
	$button = '<button title="Thêm" class="add button" name="btadd" value="btadd" type="submit"></button>';
	$button .= '<button title="Sửa" class="edit button" name="btedit" value="btedit" type="submit"></button>';
	$button .= '<button title="Xóa" class="delete button" name="btdelete" value="btdelete" type="submit"></button>';
	$button .= '<button class="able button" name="btable" value="btable" type="submit"></button>';
	$button .= '<button class="check button" name="btcheck" value="btcheck" type="submit"></button>';
	$button .= '<button title="Trang chủ" class="option button" name="btoption" value="btoption" type="submit"></button>';
	break;
	default:
		;
	break;
}
?>
<form method="post" enctype="multipart/form-data">
<div class="nav">
	<div class="navbutton">
		<?php echo $button;?>
	</div>
</div>
<div class="sheet">
	<div class="mana-title"><?php echo $title?></div>
	<?php if(isset($this->msg)) echo '<div class="message">'.$this->msg.'</div>'?>
	<div class="intro newsedit">
		<div class="form">
		<div class="big edit">
<?php 
	if($this->task != 'list'){
		if($this->task == 'edit'){
			$form = new Administrator_Form_Product($this->id);
			$form->render();
			$inf0 = $model->GetProductInfo($this->id);
			echo '<div class="tabcontroll"><ul>';
			echo '<li class="tab active" title="intro"><a href="#">Thông tin sản phẩm</a></li>';
			echo '<li class="tab" title="attribute"><a href="#">Thuộc tính sản phẩm</a></li>';
			echo '<li class="tab" title="warranty"><a href="#">Thông tin bảo hành</a></li>';
			echo '</ul></div>';
			echo '<div class="clear"></div>';
			echo '<div class="texteditor">';
			echo '<div class="intro text">';
			echo $this->textEditor('intro', $inf0['intro'],'99%','500px');
			echo '</div>';
			echo '<div class="attribute text" style="display:none;">';
			echo $this->textEditor('attribute',$inf0['attribute'],'99%','500px');
			echo '</div>';
			echo '<div class="warranty text" style="display:none;">';
			echo $this->textEditor('warranty', $inf0['warranty'],'99%','500px');
			echo '</div>';
			echo '</div>';
		}
		if($this->task == 'new'){
			$form = new Administrator_Form_Product('');
			$form->render();
			echo '<div class="tabcontroll"><ul>';
			echo '<li class="tab active" title="intro"><a href="#">Thông tin sản phẩm</a></li>';
			echo '<li class="tab" title="attribute"><a href="#">Thuộc tính sản phẩm</a></li>';
			echo '<li class="tab" title="warranty"><a href="#">Thông tin bảo hành</a></li>';
			echo '</ul></div>';
			echo '<div class="clear"></div>';
			echo '<div class="texteditor">';
			echo '<div class="intro text">';
			echo $this->textEditor('intro', "",'99%','500px');
			echo '</div>';
			echo '<div class="attribute text" style="display:none;">';
			echo $this->textEditor('attribute', "",'99%','500px');
			echo '</div>';
			echo '<div class="warranty text" style="display:none;">';
			echo $this->textEditor('warranty', "",'99%','500px');
			echo '</div>';
			echo '</div>';
		}?>
	</div>
<script type="text/javascript">
$('.sheet .intro .form .tabcontroll li').click(function(){ 
	$('.sheet .intro .form .tabcontroll li.active').removeClass('active');
	$(this).addClass('active');
	var show = $(this).attr('title');
	$('.sheet .intro .form .texteditor .text').hide('slow');
	$('.sheet .intro .form .texteditor .'+show).show('slow');
	return false;
});
</script>
		
		
<?php
	}
	else {
echo '<table class="list-item">';
	echo '<thead>';
		echo '<th class="stt">STT</th>';
		echo '<th class="checkbox"><input id="selectall" type="checkbox" ></th>';
		echo '<th class="">Tên sản phẩm</th>';
		echo '<th class="">Cửa hàng</th>';
		echo '<th class="">Loại</th>';
		echo '<th class="">Danh mục</th>';
		echo '<th class="">NSX</th>';
		echo '<th class="">Giá</th>';
		echo '<th class="id" title="lượt xem">Hit</th>';
		echo '<th class="id" title="lượt bán">Sell</th>';
		echo '<th class="id" title="Khuyến mãi">KM</th>';
		echo '<th class="">Tiền tệ</th>';
		echo '<th class="action">Action</th>';
		echo '<th class="id">ID</th>';
	echo '</thead>';
	echo '<tbody>';
	$i=1;
	foreach ($model->GetAllProduct() as $value) {
		$class="";if($i%2==0)$class = 'focus';
		echo '<tr class="'.$class.'">';
			echo '<td class="stt">'.$i.'</td>';
			echo '<td class="checkbox"><input id="'.$value['id'].'" type="checkbox" name="'.$value['id'].'" ></td>';
			echo '<td class="">'.$value['name'].'</td>';
			$stinfo = $model->GetPro_storeInfo($value['store']);
			echo '<td class="">'.$stinfo['name'].'</td>';
			$tpinfo = $model->GetProduct_type($value['type']);
			echo '<td class="">'.$tpinfo['name'].'</td>';
			$catinfo = $model->GetPro_catInfo($value['cat']);
			echo '<td class="">'.$catinfo['name'].'</td>';
			$mnfinfo = $model->GetProduct_manufactInfo($value['manufact']);
			echo '<td class="">'.$mnfinfo['name'].'</td>';
			echo '<td class="">'.$value['price'].'</td>';
			echo '<td class="id">'.$value['hit'].'</td>';
			echo '<td class="id">'.$value['sell'].'</td>';
			echo '<td class="id">'.$value['sell'].'</td>';
			$curfinfo = $model->GetPro_curInfo($value['currency']);
			echo '<td class="">'.$curfinfo['name'].'</td>';
			echo '<td class="action"><a href="'.BASE_URL.'/administrator/product/product?task=edit&id='.$value['id'].'"><img src="'.$this->dirImg.'/edit.png"></a><a href="#" onclick="DeleteSection()"><img src="'.$this->dirImg.'/delete.png"></a></td>';
			echo '<td class="id">'.$value['id'].'</td>';
			echo '</tr>';
		$i++;
	}
	echo '</tbody>';
	echo '<tfoot>';
	echo '</tfoot>';
echo '</table>';
}
?>		
		</div>
	</div>
</div>
</form>